<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Vue中的动画封装</title>
  <script src="../asset/js/vue.js"></script>
  <style>
    .fade-enter,
    .fade-leave-to {
      opacity: 0;
    }

    .fade-enter-active,
    .fade-leave-active {
      transition: opacity 1s;
    }
  </style>
</head>

<body>
  <div id="root">
    <fade :show='show'>
      <div>Hello World</div>
    </fade>
    <fade :show='show'>
      <h3>Hello World</h3>
    </fade>
    <button @click='handleClick'>切换</button>
  </div>
  <script>
    Vue.component('fade', {
      props: ['show'],
      template: `
        <transition>
          <slot v-if='show'></slot>
        </transition>
      `
    })
    let vm = new Vue({
      el: '#root',
      data: {
        show: true
      },
      methods: {
        handleClick() {
          this.show = !this.show
        }
      }
    })
  </script>
</body>

</html>